package com.dmz.wxcp.config;

import com.dmz.wxcp.interceptor.SignatureInterceptor;
import com.dmz.wxcp.wecom.common.service.RedisService;
import com.dmz.wxcp.wecom.contact.service.ContactService;
import com.dmz.wxcp.wecom.signature.service.MP_OAuth2Service;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class LoginConfig implements WebMvcConfigurer {

    @Autowired
    private RedisService redisService;

    @Autowired
    private WxMpService wxMpService;

    @Autowired
    private MP_OAuth2Service cpOAuth2Service;

    @Autowired
    private ContactService contactService;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(
                new SignatureInterceptor(redisService,contactService,wxMpService,cpOAuth2Service));
        registration.addPathPatterns("/mywechat/**");                      //所有路径都被拦截
        registration.addPathPatterns("/factory/**");                      //所有路径都被拦截
        registration.addPathPatterns("/product/**");                      //所有路径都被拦截
        registration.addPathPatterns("/transport/**");                      //所有路径都被拦截
        registration.excludePathPatterns(                         //添加不拦截路径
                "/templates/*.html",            //html静态资源
                "/static/*.js",              //js静态资源
                "/static/*.css" ,       //css静态资源
                "/wx/redirect/**",
                "/wx/menu/**",
                "/factory/getfactory",
                "/product/getproduct",
                "/transport/getlist",
                "/study/getstudyarticlelist",
                "/mywechat/searchtags"

        );
    }
}